package android.ijiajiao.server.impl;

import java.util.ArrayList;

import android.ijiajiao.dao.impl.FriendDaoImpl;
import android.ijiajiao.server.FriendServer;
import net.sf.json.JSONObject;

public class FriendServerImpl implements FriendServer {
	/**
	 * 添加好友
	 */
	@Override
	public JSONObject addFriend(String name, String friend_name) {
		JSONObject data = new JSONObject();
		boolean flag = new FriendDaoImpl().addFriend(name, friend_name);
		if (flag == false) {
			data.put("result", 0);
			data.put("data", "添加好友失败");
		} else {
			data.put("result", 1);
			data.put("data", "添加好友成功");
		}
		return data;
	}

	/**
	 * 好友列表
	 */
	@Override
	public JSONObject friend(String name) {
		JSONObject data = new JSONObject();
		ArrayList<Object> datalist = new FriendDaoImpl().friend(name);
		if (datalist.isEmpty()) {
			data.put("result", 0);
			data.put("data", "添加好友失败");
		} else {
			data.put("result", 1);
			data.put("data", datalist);
		}
		return data;
	}

	/*
	 * 查找好友 (non-Javadoc)
	 * 
	 * @see android.ijiajiao.server.FriendServer#findfriend(java.lang.String)
	 */
	@Override
	public JSONObject findfriend(String name) {
		JSONObject data = new JSONObject();
		ArrayList<Object> datalist = new FriendDaoImpl().findfriend(name);
		if (datalist.isEmpty()) {
			data.put("result", 0);
			data.put("data", "添加好友失败");
		} else {
			data.put("result", 1);
			data.put("data", datalist);
		}
		return data;
	}

}
